#coding=utf-8
import serial

ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=1);

def send_text(text):
    while 1 :
        ser.write(text.encode("utf-8"))
        reply = ser.read(1)
        ser.flushInput()
        reply = reply.decode("utf-8")
        if reply == text :
            print('sent:'+text)
            return (1)

def receive_text():
    if ser.inWaiting != 0 :
        text = ser.read(1)
        ser.flushInput()
        return (text)
    else:
        return 'none'
